package app.fugema.shop.main.order.adapter;

import com.base.common.utils.DensityUtil;
import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.ada.GeneralRecyclerAdapter;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseViewHolder;

import androidx.lifecycle.LifecycleOwner;
import app.fugema.shop.R;
import app.fugema.shop.databinding.ItemOrderDetailGoodsViewBinding;
import app.fugema.shop.main.order.model.OrderItem;
import app.fugema.shop.main.order.vm.OrderListVM;

public class AfterSaleSelectAdapter extends GeneralRecyclerAdapter {

    private OrderListVM orderListVM;

    public AfterSaleSelectAdapter(LifecycleOwner lifecycleOwner, OrderListVM orderListVM) {
        this.lifecycleOwner = lifecycleOwner;
        this.orderListVM = orderListVM;
        init();
    }

    @Override
    public void initMultiItemType()
    {
        //new OrderDetailGoodsItemMultiType(lifecycleOwner, orderListVM)
        putMultiItemType(new BaseItemMultiType<OrderItem, ItemOrderDetailGoodsViewBinding>()
        {
            @Override
            public int getLayoutId()
            {
                return R.layout.item_order_detail_goods_view;
            }

            @Override
            public void onBindViewHolder(ItemOrderDetailGoodsViewBinding binding, int position, BaseViewHolder viewHolder, OrderItem bean)
            {
                super.onBindViewHolder(binding, position, viewHolder, bean);
                if (viewHolder.getAdapter() != null)
                {
                    int firstPos = viewHolder.getAdapter().getFirstPosition(BaseItemMultiType.TYPE_CHILD, 0);
                    if (firstPos == position)
                    {
                        binding.clItemView.getDelegate().setCornerRadius_TR(DensityUtil.getDimens(R.dimen.dp_10));
                        binding.clItemView.getDelegate().setCornerRadius_TL(DensityUtil.getDimens(R.dimen.dp_10));
                    }
                    else
                    {
                        binding.clItemView.getDelegate().setCornerRadius_TR(0);
                        binding.clItemView.getDelegate().setCornerRadius_TL(0);
                    }
                    int lastPos = viewHolder.getAdapter().getLastPosition();
                    if( lastPos != -1 &&  lastPos == position  )
                    {
                        binding.clItemView.getDelegate().setCornerRadius_BR(DensityUtil.getDimens(R.dimen.dp_10));
                        binding.clItemView.getDelegate().setCornerRadius_BL(DensityUtil.getDimens(R.dimen.dp_10));
                    }
                    else
                    {
                        binding.clItemView.getDelegate().setCornerRadius_BR(0);
                        binding.clItemView.getDelegate().setCornerRadius_BL(0);
                    }
                }

                StringBuffer specSb = new StringBuffer();
                if(UIUtils.isNotEmpty( bean.getSize() ))
                {
                    specSb.append( bean.getSizeAlias() ).append(":").append(bean.getSize()).append(" ");
                }
                if(UIUtils.isNotEmpty( bean.getColor() ))
                {
                    specSb.append( bean.getColorAlias() ).append(":").append(bean.getColor()).append(" ");
                }
                if(UIUtils.isNotEmpty( bean.getVersion() ))
                {
                    specSb.append( bean.getVersionAlias() ).append(":").append(bean.getVersion());
                }
                binding.tvSpecification.setText( specSb.toString() );
            }
        });

    }


}
